#include "ranklist.h"
#include "ui_ranklist.h"
#include "game.h"
#include "ui_gameinterface.h"
#include "ui_scorerank.h"
#include "ui_timerank.h"
#include <string>
#include "database.h"
using namespace std;

ranklist::ranklist(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ranklist)
{
    ui->setupUi(this);
    DatabaseMysql *dr = new DatabaseMysql();
    db = dr->db;
    setWindowFlags(Qt::FramelessWindowHint);
    QSqlQuery result = db.exec(" select * from users order by score desc limit 10");
    int i = 1;
    while (result.next()) {
        QString id = QString::number(i);
        i++;
        string Account = result.value("username").toString().toStdString();
        QString acc = QString::fromStdString(Account);
        string Score = result.value("score").toString().toStdString();
        QString sco = QString::fromStdString(Score);
        ui->textEdit->append("第" + id + "名: " + acc + " 得分为: " + sco);
    }
}

ranklist::~ranklist()
{
    delete ui;
}

void ranklist::on_pushButton_clicked()
{
    this->close();
    game* g = new game;
    g->show();
}

